import 'dart:convert' show json;

import 'package:flutter_common_app/data/protection.dart';

class CalendarEventsData {
  CalendarEventsData({
    this.id,
    this.eventType,
    this.onlineTime,
    this.offlineTime,
    this.tag,
    this.title,
    this.imgUrl,
    this.canRemind,
    this.reminded,
    this.targetUrl,
    this.remindText,
    this.logInfo,
    this.alg,
    this.resourceType,
    this.resourceId,
    this.eventStatus,
    this.remindedText,
    this.statusText,
    this.statusTextColor,
    this.headline,
    this.subCount,
    this.extInfo,
  });

  factory CalendarEventsData.fromJson(Map<String, dynamic> jsonRes) =>
      jsonRes == null
          ? null
          : CalendarEventsData(
              id: asT<String>(jsonRes['id']),
              eventType: asT<String>(jsonRes['eventType']),
              onlineTime: asT<int>(jsonRes['onlineTime']),
              offlineTime: asT<int>(jsonRes['offlineTime']),
              tag: asT<String>(jsonRes['tag']),
              title: asT<String>(jsonRes['title']),
              imgUrl: asT<String>(jsonRes['imgUrl']),
              canRemind: asT<bool>(jsonRes['canRemind']),
              reminded: asT<bool>(jsonRes['reminded']),
              targetUrl: asT<String>(jsonRes['targetUrl']),
              remindText: asT<String>(jsonRes['remindText']),
              logInfo: asT<Object>(jsonRes['logInfo']),
              alg: asT<Object>(jsonRes['alg']),
              resourceType: asT<String>(jsonRes['resourceType']),
              resourceId: asT<String>(jsonRes['resourceId']),
              eventStatus: asT<String>(jsonRes['eventStatus']),
              remindedText: asT<String>(jsonRes['remindedText']),
              statusText: asT<Object>(jsonRes['statusText']),
              statusTextColor: asT<Object>(jsonRes['statusTextColor']),
              headline: asT<bool>(jsonRes['headline']),
              subCount: asT<int>(jsonRes['subCount']),
              extInfo: asT<Object>(jsonRes['extInfo']),
            );

  String id;
  String eventType;
  int onlineTime;
  int offlineTime;
  String tag;
  String title;
  String imgUrl;
  bool canRemind;
  bool reminded;
  String targetUrl;
  String remindText;
  Object logInfo;
  Object alg;
  String resourceType;
  String resourceId;
  String eventStatus;
  String remindedText;
  Object statusText;
  Object statusTextColor;
  bool headline;
  int subCount;
  Object extInfo;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'id': id,
        'eventType': eventType,
        'onlineTime': onlineTime,
        'offlineTime': offlineTime,
        'tag': tag,
        'title': title,
        'imgUrl': imgUrl,
        'canRemind': canRemind,
        'reminded': reminded,
        'targetUrl': targetUrl,
        'remindText': remindText,
        'logInfo': logInfo,
        'alg': alg,
        'resourceType': resourceType,
        'resourceId': resourceId,
        'eventStatus': eventStatus,
        'remindedText': remindedText,
        'statusText': statusText,
        'statusTextColor': statusTextColor,
        'headline': headline,
        'subCount': subCount,
        'extInfo': extInfo,
      };

  @override
  String toString() {
    return json.encode(this);
  }

  static fromJsonList(jsonList) {
    return jsonList
        .map<CalendarEventsData>((obj) => CalendarEventsData.fromJson(obj))
        .toList();
  }
}
